<?php
// $Id$

/**
 * Controller_Admin_Web 控制器
 */
class Controller_Admin_course extends Controller_Abstract {
	

	//课程
	function actionindex(){
		$append = array("acct_id"=>$_SESSION['acct']['id']);
		$this->union_table = papercourse::meta();
		if($this->_context->subject_id){
			$this->_view['subject_id']=$this->_context->subject_id;
		}
		$this->lists($append);
	}
	function actionAdd(){
		$this->union_table = papercourse::meta ();
	    $handle = new helper_autoinsert ( $this->union_table );
	    $form = new Form_course_add ( url ( $this->_context->controller_name . '/' . $this->_context->action_name ) );
	    //这里面会自动将get方式获取的参数传递到表单里面去的
	    $result = $handle->add ( $form, 'id', $_GET );
	    if ($this->_context->isGET ()) {
	        //传递$form值
	        $this->_view ['form'] = $result;
	        $this->_viewname = '../form/add';
	        $form->element('acct_id')->value= $_SESSION['acct']['id'];
	        $form->element('viplevel')->items= viplevel::selectviplevel($_SESSION['acct']['id']);
	        $form->element('viplevel')->value= explode(',', $form->element('viplevel')->value);
	        if(!$this->_context->id){
	        	$form->element('subject_id')->value= $this->_context->subject_id;
	        }
	    } else {
	        //记录日志
	        if(!$_POST['id'])	{
	            Syslog::logs ( '添加课程,id :' . $handle->form_database_obj->id );
	        }else{
	            Syslog::logs ( '编辑课程,id :' . $handle->form_database_obj->id );
	        }
	         
	        if($handle->status=='success')
	           $this->_context->forwardUrl = url("course").'/index/subject_id/'.$handle->form_database_obj->subject_id;
	        return call_user_func_array(array($this,$handle->status),array($result));
	    }

		
	}
	function actionDel(){
		Syslog::logs("删除课程，ID：".print_r($this->_context->ids,true));
	     $this->union_table = papercourse::meta();
	     $this->delete(array('id'=>$this->_context->ids));
	}
	

}


